﻿using ETA.ClientService;
using ETA.Common;
using ETA.DtoMappings;
using ETA.IService;
using Ninject;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETA.UnitTest
{
    [TestFixture]
    public class FileTest
    {
        private static IFileTypeService _FileTypeService { set; get; }
        private static IUploadFileService _UploadFileService { set; get; }
        private static IDocumentService _DocumentService { set; get; }
        private static IBannerService _BannerService { set; get; }

        [SetUp]
        public void Init()
        {
            DtoMapConfig.InitMap();
            IKernel kernel = new StandardKernel(new NinjectModuleBuild());
            _FileTypeService = kernel.Get<IFileTypeService>();
            _UploadFileService = kernel.Get<IUploadFileService>();
            _DocumentService = kernel.Get<IDocumentService>();
            _BannerService = kernel.Get<IBannerService>();
        }

        [Test]
        public void TestQueryBanner()
        {
            var res = _BannerService.QueryFeatureBannerList(new QueryBannerRequest { 
                 BannerKind ="App引导图"
            });
            if (res.Result.IsSuccess)
            {
                var banners = res.BannerList;
                Assert.True(banners.Count() ==3);
            }
        }

        [Test]
        public void TestSendMsg()
        {
            var res = CommHelper.SendMsg("18221647820", "6606");
            Assert.True(res);
        }


        [Test]
        public void AddFileTest()
        {
            var req = new QueryFileTypeRequest
            {
                FileTypeName = "国内派遣机构资料下载"
            };
            var response = _FileTypeService.QueryFileType(req);
            if (response.FileTypeList.Any())
            {
                var fileType = response.FileTypeList.FirstOrDefault();

                var createUploadFileRequest = new CreateUploadFileRequest
                {
                    UploadFile = new Entity.UploadFile
                    {
                        FileType = fileType,
                        FileName = DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + ".doc",
                        UploadFileId = Guid.NewGuid().ToString(),
                        IsDelete = false
                    }
                };
                _UploadFileService.CreateUploadFile(createUploadFileRequest);
            }
        }

        [Test]
        public void AddDocTest()
        {
            var rep = _UploadFileService.QueryUploadFileList(new QueryUploadFileRequest
            {
                UploadFileId = "56fab9f0-4432-43ff-9a66-b7a22c36fc58"
            });
            if (rep.Result.IsSuccess)
            {
                var file = rep.UploadFileList.FirstOrDefault();
                var res2 = _DocumentService.CreateDocument(new CreateDocumentRequest
                {
                    Document = new Entity.Document
                    {
                        DocumentId = Guid.NewGuid().ToString(),
                        DocNo = "CH-2014-0002",
                        Title = "《赴日技能实习生培训考题》",
                        Target = "赴日技能实习生",
                        Version = "2014-05-17",
                        ContentRefrence = "出国直通车平台",
                        UploadFile = file
                    }
                });
                Assert.True(res2.Result.IsSuccess);
            }
        }
        [Test]
        public void QueryDocTest()
        {
            var req = new QueryFileTypeRequest
       {
           FileTypeName = "国内派遣机构资料下载"
       };
            var response = _FileTypeService.QueryFileType(req);
            if (response.FileTypeList.Any())
            {
                var fileType = response.FileTypeList.FirstOrDefault();
                var res = _DocumentService.QueryDocumentList(new QueryDocumentRequest { FileTypeId = fileType.FileTypeId });
                Assert.True(res.Result.IsSuccess);
            }
        }
         [Test]
        public void EmailTest()
        {
            Logger.Log.Info("Test");
            var res =CommHelper.SendEmail("longfeiit@126.com","测试邮件内容","找回密码测试");
            Assert.True(res);
        }

         [Test]
         public void EncryptTest()
         {
             var encrypt = CommHelper.Base64Encrypt("123456");
             Logger.LogInfo("密文:" + encrypt);
             var dencrypt = CommHelper.Base64Dencrypt(encrypt);
             Logger.LogInfo("解密文:" + dencrypt);
             Assert.True(dencrypt=="123456");
         }

        [Test]
         public void FileTypeCachTest()
         {
             var res = FileBll.GetFileTyes();
             Assert.True(res.Count()>3);
         }

    }
}
